package com.zcx.qshop.view;

import android.content.Context;
import android.net.Uri;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;

import com.facebook.drawee.view.SimpleDraweeView;
import com.zcx.qshop.QSApplication;
import com.zcx.qshop.R;
import com.zcx.qshop.conn.JsonActivityAsyGet;
import com.zcx.qshop.flow.CircleFlowIndicator;
import com.zcx.qshop.flow.ViewFlowAdvert;

/**
 * Created by Administrator on 2015/8/9 0009.
 */
public class ActivitvBannerView extends ViewFlowAdvert<JsonActivityAsyGet.Banner> {

    private LayoutInflater layoutInflater;

    private OnItemClickListener onItemClickListener;

    public ActivitvBannerView(Context context, AttributeSet attrs) {

        super(context, attrs);

        layoutInflater = LayoutInflater.from(context);

    }

    @Override
    protected View loadView(View view, final JsonActivityAsyGet.Banner banner) {

        SimpleDraweeView simpleDraweeView = (SimpleDraweeView) view.findViewById(R.id.item_activitv_banner_img);

        simpleDraweeView.setImageURI(Uri.parse(banner.picurl));

        view.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                if(onItemClickListener != null){

                    onItemClickListener.onItemClick(banner);

                }

            }

        });

        return view;

    }

    @Override
    protected View createView() {

        return layoutInflater.inflate(R.layout.item_activitv_banner, null);

    }

    @Override
    protected View indicatorLayout(CircleFlowIndicator circleFlowIndicator) {

        circleFlowIndicator.setRadius(QSApplication.ScaleScreenHelper.getWidthHeight(9));

        circleFlowIndicator.setCircleSeparation(QSApplication.ScaleScreenHelper.getWidthHeight(27));

        return circleFlowIndicator;

    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener){

        this.onItemClickListener = onItemClickListener;

    }

    public interface OnItemClickListener{

        void onItemClick(JsonActivityAsyGet.Banner banner);

    }

}
